home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_gen / gcoope10.zip / LONGINT.C < prev    next >
Text File  |  1994-07-22  |  3KB  |  146 lines

  1.  
  2. /*
  3.  
  4.     LongInt class definition   7/13/94 by Brian Lee Price
  5.  
  6.     Compatible with experimental strong typing option.
  7.  
  8.     Released as Public Domain   July, 1994.
  9.  
  10. */
  11.  
  12. #define CLASS LongInt
  13.  
  14. #include "gcoope10.h"
  15.  
  16. #include <stdio.h>
  17.  
  18. object CLASS;
  19.  
  20. extern object String;
  21. extern object Char;
  22. extern object ShortInt;
  23. extern object Unsigned;
  24. extern object Pointer;
  25.  
  26. USEGEN(changeVal);
  27. USEGEN(valueOf);
  28. USEGEN(asString);
  29. USEGEN(asHexStr);
  30. USEGEN(asChar);
  31. USEGEN(asShortInt);
  32. USEGEN(asUnsigned);
  33. USEGEN(asPointer);
  34. USEGEN(asLongInt);
  35.  
  36. cmethod object m4New(object instance, long initVal)
  37. {
  38. long * ivptr;
  39.  
  40. if(NULL==(ivptr=makeInst(&instance))) return 0;
  41. *ivptr=initVal;
  42.  
  43. return instance;
  44. }
  45.  
  46.  
  47. imethod object m4changeVal(object instance, long newVal)
  48. {
  49. long * ivptr;
  50.  
  51. if(NULL==(ivptr=getIVptr(instance))) return FUNCFAIL;
  52. *ivptr=newVal;
  53.  
  54. return FUNCOKAY;
  55. }
  56.  
  57.  
  58. imethod long m4valueOf(object instance)
  59. {
  60. return *((long *) getIVptr(instance));
  61. }
  62.  
  63.  
  64. imethod object m4asString(object instance)
  65. {
  66. char strBuf[16];
  67. long a;
  68.  
  69. a=*((long *) getIVptr(instance));
  70. sprintf(strBuf,"%ld", a);
  71. return g(New)(String,strBuf);
  72. }
  73.  
  74.  
  75. imethod object m4asHexStr(object instance)
  76. {
  77. char strBuf[16];
  78. long a;
  79.  
  80. a=*((long *) getIVptr(instance));
  81. sprintf(strBuf, "%lx", (unsigned long) a);
  82. return g(New)(String,strBuf);
  83. }
  84.  
  85.  
  86. imethod object m4asChar(object instance)
  87. {
  88. long a;
  89.  
  90. a=*((long *) getIVptr(instance));
  91. return g(New)(Char,(char) a);
  92. }
  93.  
  94.  
  95. imethod object m4asShortInt(object instance)
  96. {
  97. long a;
  98.  
  99. a=*((long *) getIVptr(instance));
  100. return g(New)(ShortInt,(short) a);
  101. }
  102.  
  103.  
  104. imethod object m4asUnsigned(object instance)
  105. {
  106. long a;
  107.  
  108. a=*((long *) getIVptr(instance));
  109. return g(New)(Unsigned,(unsigned short) a);
  110. }
  111.  
  112.  
  113. imethod object m4asPointer(object instance)
  114. {
  115. long a;
  116.  
  117. a=*((long *) getIVptr(instance));
  118. return g(New)(Pointer,(void *) a);
  119. }
  120.  
  121.  
  122.  
  123.  
  124. CLASS_INSTALL
  125. {
  126. stat x=FUNCFAIL;
  127.  
  128. if(END==(CLASS=g(New)(Class, 0, sizeof(long), END)))
  129.     goto end;
  130. if(addGMthd(CLASS, New, (method) m4New)) goto end;
  131. if(addGMthd(CLASS, GEN(changeVal), (method) m4changeVal)) goto end;
  132. if(addGMthd(CLASS, GEN(valueOf), (method) m4valueOf)) goto end;
  133. if(addGMthd(CLASS, GEN(asString), (method) m4asString)) goto end;
  134. if(addGMthd(CLASS, GEN(asHexStr), (method) m4asHexStr)) goto end;
  135. if(addGMthd(CLASS, GEN(asChar), (method) m4asChar)) goto end;
  136. if(addGMthd(CLASS, GEN(asShortInt), (method) m4asShortInt)) goto end;
  137. if(addGMthd(CLASS, GEN(asUnsigned), (method) m4asUnsigned)) goto end;
  138. if(addGMthd(CLASS, GEN(asPointer), (method) m4asPointer)) goto end;
  139. if(addGMthd(CLASS, GEN(asLongInt), bounceBack)) goto end;
  140.  
  141. x=FUNCOKAY;
  142.  
  143. end:
  144. return x;
  145. }
  146.